package com.zjut.an.util.tools;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;

public class Count {
	public int date;

	public String getGuestCount(String path)
	{
		File file = new File(path);  
        long count = 0;  
        if(!file.exists()){  
            try {  
                file.createNewFile();  
            } catch (IOException e) {  
                // TODO Auto-generated catch block  
                e.printStackTrace();  
            }  
            write2File(path, 0);  
        }  
        try{  
            BufferedReader in = new BufferedReader(new FileReader(file));  
            try{  
                count = Long.parseLong(in.readLine());  
                //System.out.println("###########"+count);
                write2File(path, ++count);  
            }  
            catch (NumberFormatException e) {  
                // TODO: handle exception  
                e.printStackTrace();  
            } catch (IOException e) {  
                // TODO Auto-generated catch block  
                e.printStackTrace();  
            }  
            in.close();
        } catch (Exception e) {  
            // TODO: handle exception  
            e.printStackTrace();  
        }  
        return String.valueOf(count);
	}
	
	//写入文件的方法  
    public static void write2File(String filename, long count){  
        try{  
            PrintWriter out = new PrintWriter(new FileWriter(filename));  
            out.println(count); 
            //System.out.println("###########"+count);
            out.close();  
        } catch (IOException e) {  
            // TODO: handle exception  
            e.printStackTrace();  
        }  
    }  
}
